{% extends 'jwxt/base.html' %}

{% block title %}成绩查询 - 黄淮学院教务系统{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="mb-0">成绩查询</h5>
                <a href="{% url 'course_schedule' %}" class="btn btn-primary">返回课程表</a>
            </div>
            <div class="card-body">
                {% if grades_data.info %}
                    <div class="alert alert-info">
                        <h6>学生信息：</h6>
                        {% for info in grades_data.info %}
                            <span class="me-3">{{ info }}</span>
                        {% endfor %}
                    </div>
                {% endif %}

                {% if grades_data.grades %}
                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead class="table-dark">
                                <tr>
                                    <th scope="col">#</th>
                                    <th scope="col">课程名称</th>
                                    <th scope="col">成绩</th>
                                    <th scope="col">状态</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for grade in grades_data.grades %}
                                    <tr>
                                        <th scope="row">{{ forloop.counter }}</th>
                                        <td>{{ grade.subject }}</td>
                                        <td>
                                            <span class="badge 
                                                {% if grade.grade|floatformat:0|add:0 >= 90 %}bg-success
                                                {% elif grade.grade|floatformat:0|add:0 >= 80 %}bg-primary
                                                {% elif grade.grade|floatformat:0|add:0 >= 70 %}bg-warning
                                                {% elif grade.grade|floatformat:0|add:0 >= 60 %}bg-info
                                                {% else %}bg-danger
                                                {% endif %}">
                                                {{ grade.grade }}
                                            </span>
                                        </td>
                                        <td>
                                            {% if grade.grade|floatformat:0|add:0 >= 60 %}
                                                <span class="text-success">通过</span>
                                            {% else %}
                                                <span class="text-danger">未通过</span>
                                            {% endif %}
                                        </td>
                                    </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>

                    <div class="mt-3">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="card bg-light">
                                    <div class="card-body">
                                        <h6 class="card-title">统计信息</h6>
                                        <p class="card-text">
                                            总课程数：<strong>{{ grades_data.grades|length }}</strong><br>
                                            通过课程：<strong>
                                                {% for grade in grades_data.grades %}
                                                    {% if grade.grade|floatformat:0|add:0 >= 60 %}{{ forloop.counter0|add:1 }}{% endif %}
                                                {% endfor %}
                                            </strong>
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                {% else %}
                    <div class="alert alert-warning" role="alert">
                        <h6>暂无成绩信息</h6>
                        <p class="mb-0">请确认是否已有成绩录入，或稍后再试。</p>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}
